﻿$(function() {

    JSUtility.param.Options["Internaltype"] = "2";
    JSUtility.url = '../../Handler/AjaxHandle.ashx';
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectInfoPresenter";
    autoResize({ dataGrid: '#projectList', callback: Initlist });
    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加项目基本信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 600,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "15%");
            $('#Add').parent().next().css("left", "15%");
            $('#Add').parent().next().css("top", "15%");
            $('#Add').parent().css("top", "15%");
        }
    });
    JSUtility.window_edit_form = $("#Add").find("form");
    JSUtility.window_edit_title = "科研项目信息";
    comboboxInitial();
    $('#Add').show();
    JSUtility.replenish = function() {
        JSHelper.clearComboCheck("sp2", 'ProjectField');
    };

    JSUtility.saveReplenish = function() {
        //JSUtility.param.Options["ProjectField"] = $("#ProjectField").combobox("getValues").toString();
        JSUtility.param.Options["ProjectType"] = $("#ProjectType").combotree("getText");
        JSUtility.param.Options["ProjectPhase"] = $("#ProjectPhase").combotree("getText");
        JSUtility.param.Options["ApplyCompany"] = $("#ApplyCompany").combotree("getText");
        JSUtility.param.Options["ParticipateCompany"] = $("#ParticipateCompany").combotree("getText");
        JSUtility.param.Options["MainUndertakeCompany"] = $("#MainUndertakeCompany").combotree("getText");
        JSUtility.param.Options["UndertakeCompany"] = $("#UndertakeCompany").combotree("getText");
    };
});


function comboboxInitial() {
    $('#ProjectType').combotree({
        url: '../../../Handler/AjaxDictionaryTree.ashx?id=29'
    });
    $("#ProjectPhase").combotree({
        url: '../../../Handler/AjaxDictionaryTree.ashx?id=30'
    });
    $("#ApplyCompany").combotree({
        url: '../../../Handler/AjaxDictionaryTree.ashx?id=33'
    });
    $("#ParticipateCompany").combotree({
        url: '../../../Handler/AjaxDictionaryTree.ashx?id=33'
    });
    $("#MainUndertakeCompany").combotree({
        url: '../../../Handler/AjaxDictionaryTree.ashx?id=33'
    });
    $("#UndertakeCompany").combotree({
        url: '../../../Handler/AjaxDictionaryTree.ashx?id=33'
    });
    // JSHelper.comboboxData2("#ProjectField", 31);
    JSHelper.ajaxComboCheck('../../../Handler/AjaxComboboxData.ashx?typeId=31', 'sp2', 'ProjectField');
    JSHelper.comboboxData2("#ProjectLevel", 5);
}



function Initlist(size) {
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '项目基本信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 80, sortable: true}]],
        columns: [[
                            { title: '项目编号', field: 'ProjectNum', width: 80 },
                            { title: '项目名称', field: 'ProjectName', width: 120 },
                            { title: '项目下达时间', field: 'ProjectBriefTime', width: 100 },
                            { title: '项目立项时间', field: 'ProjectApprovalTime', width: 100 },
                            { title: '计划完成时间', field: 'PlanCompleteTime', width: 100 },
                            { title: '项目类型', field: 'ProjectType', width: 100 },
        //                            { title: '项目申请单位', field: 'ApplyCompany', width: 120 },
        //                            { title: '项目主承担单位', field: 'MainUndertakeCompany', width: 120 },
        //                            { title: '项目承担单位', field: 'UndertakeCompany', width: 120 },
        //                            { title: '项目参加单位', field: 'ParticipateCompany', width: 120 },
                            {title: '项目级别', field: 'ProjectLevel', width: 120 },
                            { title: '项目级别年度', field: 'ProjectImportance', width: 100 },
                            { title: '项目阶段', field: 'ProjectPhase', width: 100 },
                            { title: '项目涉及专业', field: 'ProjectField', width: 100 }
                        ]],
        view: detailview,
        detailFormatter: function(rowIndex, rowData) {
            var doc = '<table id="gridview" cellpadding="0" cellspacing="0"><tr>' +
	            '<td style="style="width:100px;"">项目申请单位: ' + rowData.ApplyCompany + '</td>' +
	            '<td style="style="width:100px;"">项目主承担单位: ' + rowData.MainUndertakeCompany + '</td>' +
	            '<td style="style="width:100px;"">项目承担单位:' + rowData.UndertakeCompany + '</td>' +
    	        '<td style="style="width:100px;"">项目参加单位:' + rowData.ParticipateCompany + '</td>' +
            '</tr>' +
            '<tr>' +
	            '<td style="style="width:100px;"">预算工时: ' + rowData.PrecastWorkHours + '</td>' +
	            '<td style="style="width:100px;"">完成工时:' + rowData.WorkHours + '</td>' +
	            '<td style="style="width:100px;"">剩余工时:' + rowData.SurplusWorkHours + '</td>' +
                '<td style="style="width:100px;""></td>' +
            '</tr>' +
           '</table>';
            return doc;
        },
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSHelper.clearComboCheck("sp2", 'ProjectField');
                            JSUtility.update();

                            //                            $("#ProjectType").combotree("setText", JSUtility.row.ProjectType);
                            //                            $("#ProjectPhase").combotree("setText", JSUtility.row.ProjectPhase);
                            //                            $("#ApplyCompany").combotree("setText", JSUtility.row.ApplyCompany);
                            //                            $("#ParticipateCompany").combotree("setText", JSUtility.row.ParticipateCompany);
                            //                            $("#MainUndertakeCompany").combotree("setText", JSUtility.row.MainUndertakeCompany);
                            //                            $("#UndertakeCompany").combotree("setText", JSUtility.row.UndertakeCompany);
                            //  $("#ProjectField").combobox("setValues", JSUtility.row.ProjectField.split(","));
                            JSHelper.ajaxDataBindComboCheck(JSUtility.row.ProjectField, 'sp2', 'ProjectField');
                            //                            $("#ProjectType").combotree("setValues", "");
                            //                            $("#ProjectPhase").combotree("setValues", "");
                            //                            $("#ApplyCompany").combotree("setValues", "");
                            //                            $("#ParticipateCompany").combotree("setValues", "");
                            //                            $("#MainUndertakeCompany").combotree("setValues", "");
                            //                            $("#UndertakeCompany").combotree("setValues", "");
                            JSHelper.dataBindTree("#ProjectType", JSUtility.row.ProjectType);
                            JSHelper.dataBindTree("#ProjectPhase", JSUtility.row.ProjectPhase);
                            JSHelper.dataBindTree("#ApplyCompany", JSUtility.row.ApplyCompany);
                            JSHelper.dataBindTree("#ParticipateCompany", JSUtility.row.ParticipateCompany);
                            JSHelper.dataBindTree("#MainUndertakeCompany", JSUtility.row.MainUndertakeCompany);
                            JSHelper.dataBindTree("#UndertakeCompany", JSUtility.row.UndertakeCompany);

                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }, '-',
                    {
                        text: '详细信息',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSUtility.row = JSHelper.isDatagridSelected($("#Grid"));
                            if (JSUtility.row == null) return;
                            self.parent.addTab('科研项目详细信息', "Project/ScientificProject/ProjectInfoManage.htm", 'icon-edit');
                            self.parent.project_id = JSUtility.row.ProjectNum; //JSHelper.isDatagridSelected($('#projectList'));
                        }
                    }
                  ]
    });
}


function EditProjectPrize() {
    // data = JSHelper.isDatagridSelected($('#projectList'));
    //if (data != null)
    JSHelper.addTab(null, '项目获奖信息', 'Project/ProjectInfoManage.htm');
}

